package com.example.sourcecodelearning.modules.order.listener;

import com.example.sourcecodelearning.modules.order.event.OrderEvent;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OrderEventListener implements ApplicationListener<OrderEvent> {

    @Async("threadPoolExecutor")
    @Override
    public void onApplicationEvent(@NotNull OrderEvent orderEvent) {
        log.info("监听到事件：{}", orderEvent);
    }

//    /**
//     * 写法二
//     *
//     * @param orderEvent 订单事件
//     */
//    @Async("threadPoolExecutor")
//    @EventListener
//    public void handleOperationLogEvent(OrderEvent orderEvent) {
//        log.info("监听到事件：{}", orderEvent);
//    }
}